package com.qingyun.form.filter

import android.text.InputFilter
import android.text.Spanned

class RoundInputFilter(
    private val keepDecimal: Int = 2,
) : InputFilter {
    override fun filter(
        source: CharSequence,
        start: Int,
        end: Int,
        dest: Spanned,
        dstart: Int,
        dend: Int,
    ): CharSequence? {
        val splits = dest.toString().split(".").toTypedArray()
        return if (splits.size == 2 && splits[1].length >= keepDecimal) "" else null
    }
}